from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-02-02 14:07:21.465431
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Tue, 02, Feb, 2021
Time: 14:07:25
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -45.7205
Nobs: 190.000 HQIC: -46.6356
Log likelihood: 2153.18 FPE: 2.99386e-21
AIC: -47.2586 Det(Omega_mle): 1.88688e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.458354 0.142819 3.209 0.001
L1.Burgenland 0.099441 0.074186 1.340 0.180
L1.Kärnten -0.221953 0.061380 -3.616 0.000
L1.Niederösterreich 0.128259 0.171958 0.746 0.456
L1.Oberösterreich 0.233868 0.150349 1.555 0.120
L1.Salzburg 0.201425 0.079798 2.524 0.012
L1.Steiermark 0.093735 0.107412 0.873 0.383
L1.Tirol 0.155067 0.071728 2.162 0.031
L1.Vorarlberg -0.002924 0.065583 -0.045 0.964
L1.Wien -0.131996 0.144167 -0.916 0.360
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.497508 0.176576 2.818 0.005
L1.Burgenland 0.019915 0.091720 0.217 0.828
L1.Kärnten 0.368075 0.075888 4.850 0.000
L1.Niederösterreich 0.117592 0.212603 0.553 0.580
L1.Oberösterreich -0.153654 0.185886 -0.827 0.408
L1.Salzburg 0.191532 0.098659 1.941 0.052
L1.Steiermark 0.240138 0.132801 1.808 0.071
L1.Tirol 0.139127 0.088681 1.569 0.117
L1.Vorarlberg 0.177028 0.081084 2.183 0.029
L1.Wien -0.585304 0.178243 -3.284 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.302551 0.063975 4.729 0.000
L1.Burgenland 0.106311 0.033231 3.199 0.001
L1.Kärnten -0.019718 0.027495 -0.717 0.473
L1.Niederösterreich 0.071993 0.077027 0.935 0.350
L1.Oberösterreich 0.284256 0.067348 4.221 0.000
L1.Salzburg 0.004751 0.035745 0.133 0.894
L1.Steiermark -0.018273 0.048115 -0.380 0.704
L1.Tirol 0.089368 0.032130 2.781 0.005
L1.Vorarlberg 0.111458 0.029377 3.794 0.000
L1.Wien 0.072205 0.064579 1.118 0.264
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.222005 0.072312 3.070 0.002
L1.Burgenland -0.015495 0.037562 -0.413 0.680
L1.Kärnten 0.025721 0.031078 0.828 0.408
L1.Niederösterreich 0.034862 0.087066 0.400 0.689
L1.Oberösterreich 0.386636 0.076125 5.079 0.000
L1.Salzburg 0.095731 0.040403 2.369 0.018
L1.Steiermark 0.186099 0.054385 3.422 0.001
L1.Tirol 0.038515 0.036317 1.061 0.289
L1.Vorarlberg 0.091165 0.033206 2.745 0.006
L1.Wien -0.067564 0.072995 -0.926 0.355
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.525681 0.144372 3.641 0.000
L1.Burgenland 0.064295 0.074993 0.857 0.391
L1.Kärnten 0.014444 0.062048 0.233 0.816
L1.Niederösterreich -0.006865 0.173829 -0.039 0.968
L1.Oberösterreich 0.152194 0.151985 1.001 0.317
L1.Salzburg 0.057482 0.080666 0.713 0.476
L1.Steiermark 0.115444 0.108581 1.063 0.288
L1.Tirol 0.205099 0.072508 2.829 0.005
L1.Vorarlberg 0.028682 0.066296 0.433 0.665
L1.Wien -0.145352 0.145736 -0.997 0.319
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.162678 0.101993 1.595 0.111
L1.Burgenland -0.018985 0.052979 -0.358 0.720
L1.Kärnten -0.011046 0.043834 -0.252 0.801
L1.Niederösterreich 0.131223 0.122802 1.069 0.285
L1.Oberösterreich 0.389819 0.107371 3.631 0.000
L1.Salzburg -0.025340 0.056987 -0.445 0.657
L1.Steiermark -0.028721 0.076708 -0.374 0.708
L1.Tirol 0.187859 0.051224 3.667 0.000
L1.Vorarlberg 0.039171 0.046835 0.836 0.403
L1.Wien 0.180651 0.102956 1.755 0.079
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.240455 0.131646 1.827 0.068
L1.Burgenland 0.063590 0.068382 0.930 0.352
L1.Kärnten -0.036736 0.056579 -0.649 0.516
L1.Niederösterreich -0.019734 0.158506 -0.124 0.901
L1.Oberösterreich -0.105749 0.138588 -0.763 0.445
L1.Salzburg 0.030592 0.073555 0.416 0.677
L1.Steiermark 0.398130 0.099010 4.021 0.000
L1.Tirol 0.486570 0.066116 7.359 0.000
L1.Vorarlberg 0.170451 0.060452 2.820 0.005
L1.Wien -0.225704 0.132889 -1.698 0.089
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.081699 0.158065 0.517 0.605
L1.Burgenland 0.034000 0.082105 0.414 0.679
L1.Kärnten -0.089813 0.067933 -1.322 0.186
L1.Niederösterreich 0.251874 0.190315 1.323 0.186
L1.Oberösterreich -0.003990 0.166399 -0.024 0.981
L1.Salzburg 0.231724 0.088316 2.624 0.009
L1.Steiermark 0.125565 0.118879 1.056 0.291
L1.Tirol 0.071441 0.079385 0.900 0.368
L1.Vorarlberg 0.042883 0.072584 0.591 0.555
L1.Wien 0.261634 0.159557 1.640 0.101
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.593290 0.083485 7.107 0.000
L1.Burgenland -0.025540 0.043365 -0.589 0.556
L1.Kärnten -0.002153 0.035880 -0.060 0.952
L1.Niederösterreich -0.041322 0.100518 -0.411 0.681
L1.Oberösterreich 0.286245 0.087887 3.257 0.001
L1.Salzburg 0.016760 0.046646 0.359 0.719
L1.Steiermark 0.018148 0.062788 0.289 0.773
L1.Tirol 0.078228 0.041929 1.866 0.062
L1.Vorarlberg 0.138759 0.038337 3.619 0.000
L1.Wien -0.057719 0.084273 -0.685 0.493
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.144459 0.030399 0.213590 0.262709 0.074784 0.094733 -0.055116 0.173154
Kärnten 0.144459 1.000000 0.015934 0.190375 0.162068 -0.114727 0.163470 0.024615 0.311910
Niederösterreich 0.030399 0.015934 1.000000 0.316913 0.093637 0.225954 0.155078 0.057663 0.371394
Oberösterreich 0.213590 0.190375 0.316913 1.000000 0.304292 0.307674 0.121876 0.082430 0.137083
Salzburg 0.262709 0.162068 0.093637 0.304292 1.000000 0.158089 0.066638 0.085873 -0.013377
Steiermark 0.074784 -0.114727 0.225954 0.307674 0.158089 1.000000 0.116980 0.095273 -0.085658
Tirol 0.094733 0.163470 0.155078 0.121876 0.066638 0.116980 1.000000 0.162249 0.157199
Vorarlberg -0.055116 0.024615 0.057663 0.082430 0.085873 0.095273 0.162249 1.000000 0.076576
Wien 0.173154 0.311910 0.371394 0.137083 -0.013377 -0.085658 0.157199 0.076576 1.000000